package eu.expressis.eiaf.core.infrastructure.integration.db.dao;

import java.io.Serializable;
import java.util.Collection;

import eu.expressis.eiaf.core.infrastructure.integration.db.entity.AbstractEntity;

public interface DefaultDao<E extends AbstractEntity> {

  /**
   * Return the number of instances of E in the persistent store.
   * 
   * @return
   */
  long getTotalCount();

  /**
   * Find all instances of this entity.
   * 
   * @return
   */
  Collection<E> findAllEntities();

  /**
   * Find an instance by its primary key.
   * 
   * @param pk the primary key
   * @return the instance
   */
  E findByPrimaryKey(Serializable pk);

  /**
   * Create a new instance and store it in the persistent store.
   * 
   * @param e the new instance
   * @return the instance updated with its primary key
   */
  E persist(E e);

  /**
   * Save changes to an existing instance. Also use this to reattach a detached instance into the persistence context.
   * 
   * @param e the instance
   * @return the updated & refreshed instance
   */
  E merge(E e);

  /**
   * Remove the entity from the persistent store
   * 
   * @param e the entity to be removed
   */
  void remove(E e);

  /**
   * Remove the entity identified by this primary key from the persistent store.
   * 
   * @param pk
   */
  void removeByPrimaryKey(Serializable pk);
}